<template>
    <div id="fish_contanier">
        <router-view/>
        <!-- <div id="loading" v-show="loading"><Spin fix>加载中...</Spin></div> -->
        <div class="pre">
            <img src="@/assets/images/assitorQRcode.png" alt="">
            <img src="@/assets/images/logoTop.png" alt="">
            <img src="@/assets/images/poster_head.png" alt="">
        </div>
    </div>
</template>

<script>
  import '@/assets/css/base.css';
  // import { mapGetters } from 'vuex';
  // import '@/vconsole.js';

  import shareArrow from '@/assets/images/share_arrow.png'

  var wx = require("weixin-js-sdk");
  import {mapActions} from 'vuex';
  import axios from 'axios'

  export default {
    name: 'App',
    // computed:{
    //   ...mapGetters({
    //     loading:'fishH5/loading'
    //   })
    // }

    data() {
      return {
        shareArrow,
        showPage: false,
        code: ''
      }
    },
    created() {
      this.code = this.getQueryString('code')
      this.goGet()
    },
    mounted() {
      let myherf = location.href.split('#')[0];
      this.getShareInfo({
        url: myherf,
        callback: res => {
          wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.data.appId, // 必填，公众号的唯一标识
            timestamp: res.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
            signature: res.data.signature, // 必填，签名
            jsApiList: [
              "updateAppMessageShareData",
              "updateTimelineShareData",
              "onMenuShareAppMessage",
              "onMenuShareTimeline",
            ]
          });

          wx.ready(() => {
            const option = {
              title: '全民助力农民工春节回家路',
              desc: '做春节专列公益志愿者，有机会得回家火车票...',
              link: 'http://zhiyang.yizehd.com/zhuli',
              imgUrl: 'http://zhiyang.yizehd.com/static/shareimg/zhuli.jpg',
            }
            // 微信分享给朋友
            wx.updateAppMessageShareData({
              title: option.title,
              link: option.link,
              imgUrl: option.imgUrl,
              desc: option.desc,
              success() {
              },
              cancel() {
                // 用户取消分享后执行的回调函数
              }, fail() {
                // alert("分享失败！"+JSON.stringify(s));
              }
            })
            wx.onMenuShareAppMessage({
              title: option.title,
              link: option.link,
              imgUrl: option.imgUrl,
              desc: option.desc,
              success() {
              },
              cancel() {
                // 用户取消分享后执行的回调函数
              }, fail() {
                // alert("分享失败！"+JSON.stringify(s));
              }
            })
            // 微信分享到朋友圈
            wx.updateTimelineShareData({
              title: option.title,
              link: option.link,
              imgUrl: option.imgUrl,
              desc: option.desc,
              success() {
              },
              cancel() {
              }, fail() {
              }
            })
            wx.onMenuShareTimeline({
              title: option.title,
              link: option.link,
              imgUrl: option.imgUrl,
              desc: option.desc,
              success() {
              },
              cancel() {
              }, fail() {
              }
            })
          })

        }
      });
    },
    methods: {
      ...mapActions({
        getShareInfo: "fishH5/getShareInfo",
      }),
      goGet() {
        const token = window.localStorage.getItem('token')
        if (token) {
          this.getZhuli()
        }
        if (!token) {
          if (!this.code) {
            this.shouquan();
            return
          }
          this.getUserByCode()
        }
      },
      shouquan() {
        const index_url = 'http://zhiyang.yizehd.com/zhuli'
        window.localStorage.removeItem('token')
        window.location.href = 'http://zhiyang.yizehd.com/api/auth/auth?state=1&uri=' + index_url;
        // window.open('http://zhiyang.yizehd.com/api/auth/auth?state=1&uri=' + index_url)
        return

      },
      getQueryString(name) {
        let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        let r = window.location.search.substr(1).match(reg);
        if (r != null) {
          return unescape(r[2]);
        }
        return null;
      },
      show() {
      },
      getZhuli() {
        axios.get('/api/user/getZhuli',{
          params:{td:88}
        }).then(()=>{
          console.log('then')
        }).catch(() => {
          console.log('catch')
        })
      },
      getUserByCode() {
        axios.post('/api/auth/getUserByCode', {
          code: this.code,
          state: 1
        }).then((res) => {
          const token = res.data.description.token
          window.localStorage.setItem('token', token)
        }).catch(() => {
        })
      }
    }
  }
</script>
<style>
    .pre{
        width: 1px;
        height: 1px;
        opacity: 0;
        position: absolute;
        left: 0;
        top: 0;
        pointer-events: none;
        overflow: hidden;
    }
</style>
